﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Text;

using LMSemir.Common;
using LMSemir.Entity;

namespace LMSemir.DAC
{
    /// <summary>
    /// 用户数据访问层
    /// </summary>
    public class UserDataAccess
    {
        public static UserEntity GetUserInfo(string userName, string pwd)
        {
            UserEntity ue = new UserEntity();
            StringBuilder strSelect = new System.Text.StringBuilder();
            strSelect.AppendFormat("select * from tbTeeUser where UName='{0}' and UPwd='{1}' ", userName.Trim(), pwd.Trim());

            try
            {
                DataTable dtUser = SqlUtil.ExecuteDataSet(CommandType.Text, strSelect.ToString()).Tables[0];
                if (dtUser.Rows.Count == 1)
                {
                    foreach (DataRow dr in dtUser.Rows)
                    {
                        ue.CreateTS = Convert.ToDateTime(dr["UCreateTS"]);
                        ue.Password = dr["UPWD"].ToString();
                        ue.PerCode = dr["UPeCode"].ToString();
                        ue.Status = Convert.ToInt32(dr["UStatus"]);
                        ue.UID = Convert.ToInt32(dr["UID"]);
                        ue.UserName = dr["UName"].ToString();
                        ue.UserRole = Convert.ToInt32(dr["UserRole"]);
                    }
                }
                else
                {
                    ue.UID = -1;
                }
            }
            catch (Exception ex)
            {
                LogUtil.GetInstance().WriteDebugLog("method:GetUserInfo,error->" + ex.Message);
                throw;
            }
            return ue;
        }
    }
}
